package com.gateon.cg.bean;

import com.gateon.cg.util.DbUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * @author
 */
@Data
public class Conf {
    private String base_package;
    private String bean_package;
    private String mapper_package;
    private String mapperxml_package;
    private String service_package;
    private String controller_package;
    private String dto_package;
    private String html_package;
	private String resp_package;
	private String req_package;

	private String client_package;
	private String provider_package;
	private String 	code_author;



	private String tables;
    private String needModules;  //需要生成的模块
    private List<String> modules;
    private boolean force;// 重新生成文件
    private boolean prefix;// 表名前缀
    private boolean underline2Camel;// 是否需要将表字段转成驼峰

	private String optMark;

	//所有要生成的模块
	private static List allModules = Arrays.asList("client","bean", "controller", "provider",
			"service", "impl", "mapper", "xml","resp","req");



	public List<String> getModules() {
		List<String> modules = new ArrayList<>();
		String needModules = getNeedModules();
		if (null == needModules || needModules.equals("all")) {
			modules = allModules;
		} else {
			modules = Arrays.asList(needModules.split(","));
		}
		return modules;
	}

	public void setModules(List<String> modules) {
		this.modules = modules;
	}

	/**
	 * @return
	 */
	public Conf getConf() {
		Properties pro = new Properties();
		try {
			pro.load(DbUtils.class.getClassLoader().getResourceAsStream("conf.properties"));
		} catch (IOException e) {
			System.out.println("未找到配置文件！！！");
		}

		String base_package = pro.getProperty("base_package");
		String bean_package = pro.getProperty("bean_package");
		String mapper_package = pro.getProperty("mapper_package");
		String mapperxml_package = pro.getProperty("mapperxml_package");
		String service_package = pro.getProperty("service_package");
		String controller_package = pro.getProperty("controller_package");
		String client_package = pro.getProperty("client_package");
		String provider_package = pro.getProperty("provider_package");

		String resp_package = pro.getProperty("resp_package");
		String req_package = pro.getProperty("req_package");
		String tables = pro.getProperty("tables");
		String needModules = pro.getProperty("needModules");
		String forceStr = pro.getProperty("force");
		String prefixStr = pro.getProperty("prefix");
		String underline2CamelStr = pro.getProperty("underline2Camel");
		String codeAuth = pro.getProperty("code_author");

		this.setBase_package(base_package);
		this.setBean_package(bean_package);
		this.setMapper_package(mapper_package);
		this.setMapperxml_package(mapperxml_package);
		this.setService_package(service_package);
		this.setController_package(controller_package);
		this.setClient_package(client_package);
		this.setProvider_package(provider_package);
		this.setTables(tables);
		this.setNeedModules(needModules);
		this.setReq_package(req_package);
		this.setResp_package(resp_package);
		this.setCode_author(codeAuth);
		boolean force = false;
		boolean prefix = true;
		boolean underline2Camel = true;
		if (StringUtils.isNotBlank(forceStr) && (forceStr.equals("true") || forceStr.equals("false"))) {
			force = Boolean.parseBoolean(forceStr);
		}
		if (StringUtils.isNotBlank(prefixStr) && (prefixStr.equals("true") || prefixStr.equals("false"))) {
			prefix = Boolean.parseBoolean(prefixStr);
		}
		if (StringUtils.isNotBlank(underline2CamelStr)
				&& (underline2CamelStr.equals("true") || underline2CamelStr.equals("false"))) {
			underline2Camel = Boolean.parseBoolean(underline2CamelStr);
		}

		this.setForce(force);
		this.setPrefix(prefix);
		this.setUnderline2Camel(underline2Camel);

		return this;
	}
}
